﻿<%@ WebHandler Language="C#" Class="WXActivity.PostHandler" %>

using System;
using System.Web;
using Activity;
using Activity.API;

namespace WXActivity
{
    /// <summary>
    /// Post一般处理程序的测试
    /// </summary>
    public class PostHandler : BaseHandler
    {
        public PostHandler()
        {
            //修改请求为post 方式
            base._httpReuqest = base.Context.Request.Form;
        }

        /// <summary>
        /// GetAccessToken
        /// </summary>
        public void GetOpenID()
        {
            var code = _httpReuqest["code"];
            if (string.IsNullOrWhiteSpace(code)) Error("无效的[Code]值");
            var result = WeixinApi.GetOpenID(code);
            if (result == null)
                Error("未找到数据");
            else
                Success(result.openid);
        }

        /// <summary>
        /// 检验用户是否注册
        /// </summary>
        public void CheckUser()
        {
            var openid = _httpReuqest["openid"];
            var result = UserPlayHandler.CheckUser(openid);
            Success(result);
        }

        /// <summary>
        /// 抽奖
        /// </summary>
        public void Lottery()
        {
            var openId = _httpReuqest["openId"];
            var lottery = new LotteryHandler();
            var result = lottery.DrawPrize(openId);
            Success(result);
        }
        /// <summary>
        /// 验证小票
        /// </summary>
        public void CheckNote()
        {
            var openid = _httpReuqest["openid"];
            var poscode = _httpReuqest["poscode"];
            var result = UserPlayHandler.CheckNote(openid, poscode);
            if (result > 0)
                Success(result);
            else
                Error("无效的小票号");
        }

        /// <summary>
        /// 个人中奖列表
        /// </summary>
        public void LotteryList()
        {
            var openId = _httpReuqest["openId"];
            var lottery = new LotteryHandler();
            var result = lottery.LotteryList(openId);
            Success(result);
        }

        public void Add()
        {
            var CardID = _httpReuqest["CardID"];
            var CardCode = _httpReuqest["CardCode"];
            var ShopID = _httpReuqest["ShopID"];
            var lottery = new LotteryHandler();
            lottery.CalculateIntegral(CardID, CardCode, ShopID);
            Success(0);
        }
    }
}